package com.yellowpage.omc.o2o.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.omc.o2o.data.CustomerExtInfo;
import com.yellowpage.omc.o2o.dao.CustomerExtInfoDao;

public class CustomerExtInfoServiceImpl extends BaseServiceImpl implements CustomerExtInfoService {
	  private CustomerExtInfoDao customerExtInfoDao;
	
	  public void setCustomerExtInfoDao(CustomerExtInfoDao customerExtInfoDao) {
		  this.customerExtInfoDao = customerExtInfoDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public CustomerExtInfo getCustomerExtInfo(Long id){
	      return customerExtInfoDao.get(id);
	  }
	  
    public List<CustomerExtInfo> getAllCustomerExtInfo(){
        return customerExtInfoDao.getAll();
    }
    
    public List<Map> queryCustomerExtInfoByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.CUSTOMER_EXT_INFO_ID , a.CUSTOMER_ID , a.EXT_INFO_ID , (select display_name from CA_USER where user_id = a.CREATE_USER) as CREATE_USER , a.CREATE_TIME , (select display_name from CA_USER where user_id = a.LAST_UPDATE_USER) as LAST_UPDATE_USER , a.LAST_UPDATE_TIME , a.VALUE    FROM OMC_CUSTOMER_EXT_INFO a WHERE 1=1 ")
				    			.addCondition(" and CUSTOMER_EXT_INFO_ID = :customerExtInfoId ")
							    			.addCondition(" and CUSTOMER_ID = :customerId ")
							    			.addCondition(" and EXT_INFO_ID = :extInfoId ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    			.addCondition(" and VALUE = :value ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveCustomerExtInfo(CustomerExtInfo customerExtInfo){
        customerExtInfoDao.save(customerExtInfo);
    }
    
	  public void updateCustomerExtInfo(CustomerExtInfo customerExtInfo){
	      customerExtInfoDao.update(customerExtInfo);
	  }
	  
	  public void delete(List deleteList){
	      customerExtInfoDao.remove(deleteList);
	  }
	  
	  
	 
	
}	